package com.lj.file.result;

import com.lj.file.entity.FileDetail;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * <p>
 * 文件记录表 分页结果
 * </p>
 *
 * @author lj
 * @since 2025-06-26 22:03:00
 */
@Data
@Schema(description = "文件记录表 分页结果")
public class FileDetailPageResult {

    @Schema(description = "主键id ")
    private Long id;

    @Schema(description = "文件访问地址 ")
    private String url;

    @Schema(description = "文件大小，单位字节 ")
    private Long size;

    @Schema(description = "原始文件名 ")
    private String originalFilename;

    @Schema(description = "文件扩展名 ")
    private String ext;

    @Schema(description = "存储平台 ")
    private String platform;

    @Schema(description = "缩略图访问路径 ")
    private String thUrl;

    @Schema(description = "缩略图名称")
    private String thFilename;

    @Schema(description = "创建时间 ")
    private LocalDateTime createTime;

    @Schema(description = "上传状态，仅在手动分片上传时使用，1：初始化完成，2：上传完成")
    private Integer uploadStatus;

    public static FileDetailPageResult of(FileDetail entity) {
        if (entity == null) {
            return null;
        }
        FileDetailPageResult result = new FileDetailPageResult();
        result.setId(entity.getId());
        result.setUrl(entity.getUrl());
        result.setSize(entity.getSize());
        result.setOriginalFilename(entity.getOriginalFilename());
        result.setExt(entity.getExt());
        result.setPlatform(entity.getPlatform());
        result.setThUrl(entity.getThUrl());
        result.setThFilename(entity.getThFilename());
        result.setCreateTime(entity.getCreateTime());
        result.setUploadStatus(entity.getUploadStatus() != null ? entity.getUploadStatus().getValue() : null);
        return result;
    }
}
